package com.hainiu.cat.web.lintcode;

/**
 * create by biji.zhao on 2021/6/8
 */
public class SolutionTest {

    private static double check(double mid, int[][] barracks) {
        double maxX = 0;
        for (int[] barrack : barracks) {
            double tmp = Math.sqrt(barrack[1] * barrack[1] + (barrack[0] - mid) * (barrack[0] - mid));
            maxX = Math.max(maxX, tmp);
        }
        return maxX;
    }

    public static double fetchSuppliesII(int[][] barracks) {
        double l = -1000;
        double r = 1000;
        double mid = 0;
        for (int i = 0; i < 100; i++) {
            // 中间位置
            mid = l + (r - l) / 2;
            // 3/4处
            double midMid = mid + (r - mid) / 2;
            if (check(mid, barracks) < check(midMid, barracks)) {
                r = mid;
            }else {
                l = midMid;
            }
            System.out.println(i);
        }
        return check(mid, barracks);
    }

    public static void main(String[] args) {
        int [][] input = {{-3303,3448}, {-6163,6529}, {-7256,9636}, {-8539,-8208}, {437,-5603}, {8071,1851}};
        double v = fetchSuppliesII(input);
        System.out.println(v);
    }
}
